var app = angular.module('JiangGanApp')
app.controller('LoginCtrl', ['$scope','$state','$rootScope',LoginCtrl]);

function LoginCtrl($scope,$state,$rootScope){
	$scope.account = ''
	$scope.password= ''

	$scope.accountPair = [
		{
			acc:'admin',
			pwd:'admin'
		},
		{
			acc:'',
			pwd:''
		}
	]

	$scope.hintOption = {
        show:false,
        hinttitle:'',
        hintinfo:'111',
        typeImg:'../img/对号.png',
        btn:'继续添加',
        cancelBtn:'返回首页'
    }

	$scope.checkKeyUp = function(e){
		var keycode = window.event ? e.keyCode : e.which;//获取按键编码  
				console.log(keycode)
            if (keycode == 13) { 
            	if($scope.hintOption.show==true){
            		$scope.hintOption.show==false;
            	} else{
            		$scope.checkLogin()//如果等于回车键编码执行方法  
            	}
               
            }  
	}

	$scope.checkLogin = function(){
		if($scope.account==''||$scope.password==''){
			$scope.password=''
			$scope.hintOption = {
		        show:true,
		        hinttitle:'请输入账号与密码！',
		        hintinfo:'',
		        typeImg:'../img/错.png',
		        btn:'确定',
		        cancelBtn:''
    		}
    		$scope.clickSubmit = function(){
    			$scope.hintOption.show = false;
    		}
		}else{
			//校验正确
			if($scope.account!='admin'||$scope.password!='admin'){
				$scope.hintOption = {
			        show:true,
			        hinttitle:'用户名不存在或密码错误！',
			        hintinfo:'',
			        typeImg:'../img/错.png',
			        btn:'确定',
			        cancelBtn:''
    			}
	    		$scope.clickSubmit = function(){
	    			$scope.hintOption.show = false;
	    		}
				$scope.password=''
			}else{
				$scope.hintOption = {
			        show:true,
			        hinttitle:'登录成功！',
			        hintinfo:'',
			        typeImg:'../img/对号.png',
			        btn:'确定',
			        cancelBtn:''
    			}
    		$scope.clickSubmit = function(){
    			$scope.hintOption.show = false;
    			$rootScope.account = $scope.account;
				$state.go('app.region.main')
    		}

			}
		}
	}

}
